package data;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.thoughtworks.xstream.annotations.XStreamAlias;

@XmlRootElement(name="compound")
@XStreamAlias("compound")
public class CompoundContainer {

	public CompoundContainer(CompoundContainer other) {
		if (other != null) {
			this.booleanvalue = other.booleanvalue;
			this.bytevalue = other.bytevalue;
			this.shortvalue = other.shortvalue;
			this.intvalue = other.intvalue;
			this.longvalue = other.longvalue;
			this.floatvalue = other.floatvalue;
			this.doublevalue = other.doublevalue;
			this.stringvalue = other.stringvalue;
			if (other.compoundvalue != null) {
				this.compoundvalue = new CompoundContainer(other.compoundvalue);
			}
		}
	}
	
	public CompoundContainer() {
	}
	
	@XmlElement
	public boolean booleanvalue;
	@XmlElement
	public byte bytevalue;
//	@XmlElement
//	public char charvalue;
	@XmlElement
	public double doublevalue;
	@XmlElement
	public float floatvalue;
	@XmlElement
	public int intvalue;
	@XmlElement
	public long longvalue;
	@XmlElement
	public short shortvalue;
	@XmlElement
	public String stringvalue;
	@XmlElement
	public CompoundContainer compoundvalue;

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (booleanvalue ? 1231 : 1237);
		result = prime * result + bytevalue;
		result = prime * result
				+ ((compoundvalue == null) ? 0 : compoundvalue.hashCode());
		long temp;
		temp = Double.doubleToLongBits(doublevalue);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result + Float.floatToIntBits(floatvalue);
		result = prime * result + intvalue;
		result = prime * result + (int) (longvalue ^ (longvalue >>> 32));
		result = prime * result + shortvalue;
		result = prime * result
				+ ((stringvalue == null) ? 0 : stringvalue.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CompoundContainer other = (CompoundContainer) obj;
		if (booleanvalue != other.booleanvalue)
			return false;
		if (bytevalue != other.bytevalue)
			return false;
		if (compoundvalue == null) {
			if (other.compoundvalue != null)
				return false;
		} else if (!compoundvalue.equals(other.compoundvalue))
			return false;
		if (Double.doubleToLongBits(doublevalue) != Double
				.doubleToLongBits(other.doublevalue))
			return false;
		if (Float.floatToIntBits(floatvalue) != Float
				.floatToIntBits(other.floatvalue))
			return false;
		if (intvalue != other.intvalue)
			return false;
		if (longvalue != other.longvalue)
			return false;
		if (shortvalue != other.shortvalue)
			return false;
		if (stringvalue == null) {
			if (other.stringvalue != null)
				return false;
		} else if (!stringvalue.equals(other.stringvalue))
			return false;
		return true;
	}
	
	public static long getSize() {
		return (1 + 8 + 16 + 32 + 64 + 32 + 64 + (16 * Constants.STRING_LENGTH)) * 3;
	}	
}
